/**
 * COPYRIGHT HangZhou Trustway Technology Company Limited
 * All right reserved.
 */
package com.robam.cloud.database.util;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description
 * @Author 薛铁琪
 * @CreateTime 2020/7/4 17:44
 * @Version 1.0
 */
@Slf4j
public class DynamicDataSourceContextHolder {
    private static final ThreadLocal<String> contextHolder = new ThreadLocal();
    public static final String DEFAULT_SOURCE = "db1";

    public static void setMyDBType(String myDBType) {
        log.debug("component-databaselog-----------change datasource to db : {} ", myDBType);
        contextHolder.set(myDBType);
    }

    public static String getMyDBType() {
        return (String) contextHolder.get();
    }

    public static void restore() {
        log.debug("component-databaselog-----------change datasource to db : {} ", DEFAULT_SOURCE);
        contextHolder.set(DEFAULT_SOURCE);
    }

    public static void clearMyDBType() {
        contextHolder.remove();
    }
}
